package net.nothinglost.renotification;

/*
    Copyright (C) 2011, Carl Reinke

    This file is part of Renotification.

    Renotification is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Renotification is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Renotification.  If not, see <http://www.gnu.org/licenses/>.
*/

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.util.Log;

public class SMSReceiver extends BroadcastReceiver
{
    @Override
    public void onReceive( Context context, Intent intent )
    {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
        
        if (!preferences.getBoolean(context.getString(R.string.service_enabled_key), true))
            return;
        
        if (!preferences.getBoolean(context.getString(R.string.sms_source_enabled_key), true))
            return;

        Log.d(context.getString(R.string.TAG), "caught SMS broadcast");

        Intent activateIntent = new Intent(context, NotificationService.class);
        activateIntent.setAction(NotificationService.ACTIVATE_ACTION);
        activateIntent.putExtra("source", getClass().getName());
        activateIntent.putExtra("active", true);
        
        context.startService(activateIntent);
    }
}
